#include <stdio.h>
#include "display_mode.h"


void screen_mode(struct drm_card hdmi_card,struct drm_plane *plane,int plane_cnt,display_mode mode,int alpha){

   static display_mode last_mode;
    unsigned int fourcc=DRM_FORMAT_RGB888;

    if(last_mode==mode){
        printf("mode same,no init\r\n");
        return;
    }
    if(last_mode!=screen_no){
//        for(int i=0;i<pipe_mode_count[last_mode];i++){
//            plane_destroy(&plane[i]);
//        }
        plane_destroy_all(plane,plane_cnt);
    }
    switch (mode) {
    case screen_no:
        break;
    case screen123456:
        init_plane(&plane[0],hdmi_card,33,1920,720,0,0,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        break;
    case screen14x25x36:
        init_plane(&plane[0],hdmi_card,33,640,720,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,640,720,640,0,fourcc);
        init_plane(&plane[2],hdmi_card,35,640,720,1280,0,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
        break;
    case screen1x25x3x4x6:
        init_plane(&plane[0],hdmi_card,33,640,360,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,640,720,640,0,fourcc);
        init_plane(&plane[2],hdmi_card,35,640,360,1280,0,fourcc);
        init_plane(&plane[3],hdmi_card,36,640,360,0,360,fourcc);
        init_plane(&plane[4],hdmi_card,37,640,360,1280,360,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 36, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 37, "alpha", alpha);
        break;
    case screen123x4x5x6:
        init_plane(&plane[0],hdmi_card,33,1920,360,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,640,360,0,360,fourcc);
        init_plane(&plane[2],hdmi_card,35,640,360,640,360,fourcc);
        init_plane(&plane[3],hdmi_card,36,640,360,1280,360,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 36, "alpha", alpha);
        break;
    case screen1x2x3x456:
        init_plane(&plane[0],hdmi_card,33,640,360,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,640,360,640,0,fourcc);
        init_plane(&plane[2],hdmi_card,35,640,360,1280,0,fourcc);
        init_plane(&plane[3],hdmi_card,36,1920,360,0,360,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 36, "alpha", alpha);
        break;
    case screen1x2x3x4x5x6:
        init_plane(&plane[0],hdmi_card,33,640,360,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,640,360,640,0,fourcc);
        init_plane(&plane[2],hdmi_card,35,640,360,1280,0,fourcc);
        init_plane(&plane[3],hdmi_card,36,640,360,0,360,fourcc);
        init_plane(&plane[4],hdmi_card,37,640,360,640,360,fourcc);
        init_plane(&plane[5],hdmi_card,38,640,360,1280,360,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 36, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 37, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 38, "alpha", alpha);
        break;
    case screen1425x2536 :
        init_plane(&plane[0],hdmi_card,33,960,720,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,960,720,960,0,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        break;
    case screen14x25x36_fzjs:
        init_plane(&plane[0],hdmi_card,34,480,720,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,33,960,720,480,0,fourcc);
        init_plane(&plane[2],hdmi_card,35,480,720,1440,0,fourcc);
//        init_plane(&plane[3],hdmi_card,36,640,655,480+110,0+20,fourcc);
//        init_plane(&plane[3],hdmi_card,38,960,720,480,0,DRM_FORMAT_NV12);
        drm_set_prop(hdmi_card.fd, 33, "alpha", 110);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
//        drm_set_prop(hdmi_card.fd, 36, "alpha", 110);
//        drm_set_prop(hdmi_card.fd, 38, "alpha", 150);
        break;
    case screen1x25x3x4x6_fzjs:
        init_plane(&plane[0],hdmi_card,33,480,360,0,0,fourcc);
        init_plane(&plane[1],hdmi_card,34,960,720,480,0,fourcc);
        init_plane(&plane[2],hdmi_card,35,480,360,1440,0,fourcc);
        init_plane(&plane[3],hdmi_card,36,480,360,0,360,fourcc);
        init_plane(&plane[4],hdmi_card,37,480,360,1440,360,fourcc);
        drm_set_prop(hdmi_card.fd, 33, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 34, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 35, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 36, "alpha", alpha);
        drm_set_prop(hdmi_card.fd, 37, "alpha", alpha);
        break;
    }
    last_mode=mode;
};
